<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<%
	if (session == null) {
%>
<jsp:forward page="SessionExpired.jsp" />
<%
	}
%>

<head>
<style type="text/css">
.timerDisplay{
	margin-left: auto;
	margin-right: auto;
	width: 52px;
	height: 20px;
	border-style: groove;
	border-color: #c0c0c0;
	text-align: right;
	font-weight: bold;
	font-size: 14pt;
	align:right;
}
.timerDisplay2{
	width: 65px;
	font-weight: bold;
	font-size: 14pt;
	
}
.ques{
	margin-left: 12cm;
	margin-right: auto;
	font-weight: bold;
	font-size: 14pt;
	
}
.timerText {	
	font-size: 12pt;
	align:right;
}

</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Aptitude Test</title>
<script type="text/javascript">

<%
String first = (String) session.getAttribute("first");
Integer itotalst = (Integer) session.getAttribute("duration");
Integer iCounter=(Integer) session.getAttribute("counter");
int tot = itotalst;
int counter=iCounter;
//System.out.println("In JSP time received is:" + tot);
//System.out.println("In JSP counter received  is:" + counter);
int min = tot / 60;
if (first == "true") {
	min = min - 1;

}
//System.out.println("In JSP min:"+ min+ " tot:" + tot);
%>
	
	var cmin = <%=min%>;
	var total = <%=tot%>;
	var ctr = <%=counter%>;
	var done  = "false";
	var dom = document.getElementById("timer");
	function startTimer() {
		var dom = document.getElementById("timer");
		var dom2=document.getElementById("itime");
		var dom3=document.getElementById("icount");
		if (total == 0) {
			timeUp();
		}
		dom.value = (cmin) + " : " + (total%60);
<%String t = (String) session.getAttribute("over");%>
var tt=<%=t%>
	if (tt == "false") {
			timeUp();
		}
		total = total - 1;
		dom2.value = total;
		ctr++;
		dom3.value = ctr;
		if (ctr == 60) {
			ctr = 0;
			cmin = cmin - 1;
		}
		if (total == 0) {
			timeUp();
		}
		if(done == false)
			{
		setTimeout("startTimer()", 1000);
			}
	}
	function timeUp() {
		done=true;
		var form=document.forms["examForm"];
		form.action="finish.action";
		form.submit();
		//window.location.replace("dummy.jsp");

	}
</script>


</head>
<body onload="done=false;startTimer()">
<s:form id="examForm" method="post">
		Time Remaining:	<input type="text" name="texttimer" id="timer" class="timerDisplay2" maxlength="4"/>
		<s:hidden id="itime" name="remainingTime"/>
		<s:hidden id="icount" name="counter"/>
		<br>
		<br>
		<p class="ques">QUESTIONS</p>
		<br>
<!--  
	<table>
		<thead>
			<tr>
				<th>QuestionNo</th>
				<th>Question</th>
			</tr>
		</thead>
		<tbody>
		-->
				<s:set name="myindex" value="%{#session.start}"/>
				 <s:iterator value="questions" status="QNO" begin="%{#session.start}" end="%{#session.end}" var="eachQuestion">
		 	
		 	  	
		 		<s:property value="%{#QNO.index + #myindex +1}"/>. 		 	
		 		<s:property value="#eachQuestion.questionContent"/>
		 		<br>
		 		<s:iterator value="#eachQuestion.options" var="opt">
		 			<s:radio theme="simple" name="answersMap['%{#eachQuestion.questionId}']" value="%{#eachQuestion.studentChoice}" list="#{optionId:content}" /> <br>
		 		</s:iterator>
		 			 		
		 		<br>
		 		<br>
		 	
		 <!--  
		 <s:hidden name="markerIndex" value="%{#QNO.index + 1}"></s:hidden>	
		 -->
		</s:iterator>
		<!--  
		</tbody>
	</table>
	-->
<s:if test="%{#session.start==0}">
	<s:if test="%{#session.end==(#session.totalQuestions-1)}">
		<s:submit value="FINISH" name="button" action="finish" align="center" theme="simple" namespace="/" />
	</s:if>
	<s:else>
		<s:submit value="NEXT" name="button" action="next" align="center" theme="simple"  namespace="/" />
	</s:else>
</s:if>
<s:elseif test="%{#session.end==(#session.totalQuestions-1)}">
<s:submit value="PREV" name="button" action="previous" align="center" theme="simple" namespace="/" />
<s:submit value="FINISH" name="button" action="finish" align="center" theme="simple" namespace="/" />
</s:elseif>
<s:else>
<s:submit value="PREV" name="button" action="previous" align="center" theme="simple" namespace="/" />
<s:submit value="NEXT" name="button" action="next" align="center" theme="simple" namespace="/" />
</s:else>


		
	
</s:form>
</body>
</html>